<?php

namespace addons\member\model;

//eth记录表
class MemberEthLog extends \web\common\model\BaseModel {

    protected function _initialize() {
        $this->tableName = 'member_eth_log';
    }

    public function getList($pageIndex = -1, $pageSize = -1, $filter = '', $order = 'l.id desc') {
        $sql = 'select l.*,m.username,m.phone from ' . $this->getTableName() .' l left join tp_member_account m on m.id = l.user_id';
        if (!empty($filter)) {
            $sql = $sql . ' where ' . $filter;
        }
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }

    /**
     * 获取记录总数
     * @param type $filter
     * @return int
     */
    public function getDataTotal($filter = '') {
        $sql = 'select count(l.id) c from ' . $this->getTableName() .' l left join tp_member_account m on m.id = l.user_id';
        if (!empty($filter)) {
            $sql = $sql . ' where ' . $filter;
        }
        $result = $this->query($sql);
        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }

    /**
     * 查询订单是否存在
     * @param type $txid 交易hash串
     */
    public function getDetailByTxid($hash){
        return $this->where('hash',$hash)->value('hash');
    }

    /**
     * 增加记录
     */
    public function addLog($data,$status = 0){
        $data['user_id'] = $data['user_id'];
        $data['hash'] = $data['hash'];
        $data['amount'] = $data['amount'];
        $data['from'] = $data['from'];
        $data['to'] = $data['to'];
        $data['timestamp'] = $data['timeStamp'];
        $data['create_time'] = NOW_DATETIME;
        $data['status'] = $status;
        return $this->add($data);
    }
}
